#ifndef	__MATRIX_KEYS_H
#define	__MATRIX_KEYS_H

#include "GPIO.h"

// 矩阵键盘行列引脚
#define ROW1 P27
#define ROW2 P50
#define ROW3 P21
#define ROW4 P23
#define COL1 P05
#define COL2 P53
#define COL3 P07
#define COL4 P06

// 按键对应行列(行-十位，列-个位)
#define BTN_A      0
#define BTN_B      1
#define BTN_X      2
#define BTN_Y      3
#define BTN_UP     10
#define BTN_DOWN   11
#define BTN_L      12
#define BTN_R      13
#define BTN_CENTER 20
#define BTN_RX1    21
#define BTN_LX1    22
#define BTN_RX2    23
#define BTN_BACK   30
#define BTN_START  31

#define UP   1 
#define DOWN 0

#define IS_KEY_UP(i, j)    ((last_state & (1 << (i * 4 + j))) > 0)
#define IS_KEY_DOWN(i, j)  ((last_state & (1 << (i * 4 + j))) == 0)
#define SET_KEY_UP(i, j)   (last_state |= (1 << (i * 4 + j)))
#define SET_KEY_DOWN(i, j) (last_state &= ~(1 << (i * 4 + j)))


// 矩阵键盘引脚配置
void GPIO_Matrix_Key_Config();


// 轮询查询哪个按键按下
void polling_keys(void (*key_down_fun)(u8 row, u8 col), void (*key_up_fun)(u8 row, u8 col));

#endif
